package red.lixiang.base;

import red.lixiang.dao.MemberDAO;
import red.lixiang.dao.OrderDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EmailTask {

    @Autowired
    private OrderDAO orderDAO;

    @Autowired
    private MemberDAO memberDAO;

//    @Scheduled(cron = "0 0 23 * * *")
//    public void sendEmailByDay(){
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        String today  = format.format(new Date());
//        //String today = "2017-10-04";
//        StringBuffer sb  = new StringBuffer("今天汉南德蒙斯特销售报表如下：\n");
//
//        //获得今天所有的订单
//        List<Order> todayOrders = orderDAO.getOrdersByTime(today,today);
//        if(todayOrders!=null && todayOrders.size()>0){
//            //获得今天的充值总金额
//            double totalCharge = todayOrders.stream().filter(o->o.getOrderStatus()==3).mapToDouble(Order::getTotalPrice).sum();
//            //获得今天总营业额(不包含充值)
//            double totalSale = todayOrders.stream().filter(o->o.getOrderStatus()!=3).mapToDouble(Order::getTotalPrice).sum();
//            //获得今天总件数
//            long totalCount = todayOrders.stream().filter(o->o.getOrderStatus()!=3).mapToInt(Order::getTotalNum).sum();
//            //获取今天新办的会员
//            List<Member> members = memberDAO.getMemberByCreateTime(today);
//            long newMemberCount = members.stream().count();
//            //老会员回头数
//            long oldMember = todayOrders.stream().filter(o->o.getOrderStatus()!=3 && o.getMemberId()!=0).count()-newMemberCount;
//
//            sb.append("时间：").append(today).append("\n");
//            sb.append("新办会员：").append(newMemberCount).append("人\n");
//            sb.append("老会员回头：").append(oldMember).append("人\n");
//            sb.append("今天充值金额为：").append(totalCharge).append("元\n");
//            sb.append("今天总营业额（不含充值）:").append(totalCount).append("件，").append(totalSale).append("元\n");
//        }else {
//            sb.append("今天行情不好，请明天再看");
//        }
//
//        sb.append("本邮件由系统自动生成，请不要回复");
//
//        String subject = "汉南德蒙斯特销售日况"+today;
//
//        IS_MailConfig mailConfig = new IS_MailConfig("smtp.mxhichina.com",25,"tongzhuang@ideashare.tech","DeMeng888");
//        mailConfig.setReceiverAddr("lixiang9409@vip.qq.com");
//        IS_MailUtils.sendSimpleBySMTP(mailConfig,subject,sb.toString());
//
//    }

}
